package advance.app.service.impl;

import advance.app.dao.DepFileInfoMapper;
import advance.app.pojo.DepFileInfo;
import advance.app.service.DepFileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepFileInfoServiceImpl implements DepFileInfoService {


    @Autowired
    DepFileInfoMapper depFileInfoMapper;

    public int saveDepFileInfo(DepFileInfo info){
        DepFileInfo depInfo = new DepFileInfo();
        int rs = 0;
        if(null != info && info.getDepFileType() != null){
            // 删除相同版本的SOP信息;
            int index = depFileInfoMapper.deleteByTypeAndVer(info.getDepArea(),info.getDepFileType(), info.getDepFileName());
            depInfo = depFileInfoMapper.getByTypeAndVer(info.getDepArea(),info.getDepFileType(), info.getDepFileName());
            if(null == depInfo){
                rs = depFileInfoMapper.saveDepFileInfo(info);
            }else{
                info.setId(depInfo.getId());
                rs = depFileInfoMapper.updateDepFileInfo(info);
            }
        }
        return rs;
    }

    public DepFileInfo getLatestInfoByType(String area,String fileType){
        return depFileInfoMapper.getLatestInfoByType(area,fileType);
    }

    public DepFileInfo getLatestInfoByMid(Integer id){
        return depFileInfoMapper.getLatestInfoByMid(id);
    }

    @Override
    public List<String> getAllVerInfoByType(String area, String fileType) {
        return null;
    }

    @Override
    public int updateDepFileInfo(DepFileInfo info) {
        return depFileInfoMapper.updateDepFileInfo(info);
    }

    public DepFileInfo getByTypeAndVer(String area,String type,String fileName){
        return depFileInfoMapper.getByTypeAndVer(area,type,fileName);
    }

    @Override
    public int deleteByTypeAndVer(String area,String fileType, String fileName) {
        return 0;
    }

    @Override
    public List<DepFileInfo> getInfoByAreaAndType(String area, String fileType) {
        return depFileInfoMapper.getInfoByAreaAndType(area,fileType);
    }

    @Override
    public List<DepFileInfo> getListByArea(String area) {
        return depFileInfoMapper.getListByArea(area);
    }

    /*public List<DepFileInfo> getListByAreaAndVer(String area,String fileType, String version) {
        return depFileInfoMapper.getListByAreaAndVer(area,fileType,version);
    }*/


}
